package com.turnengine.client.local.alliance.command;

import com.javabi.command.IExecutableCommand;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.serializer.AbstractCommandDataSerializer;
import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * The Get Invited To Join Alliance List Data Serializer.
 */
public class GetInvitedToJoinAllianceListDataSerializer extends AbstractCommandDataSerializer<List<Integer>> implements IGetInvitedToJoinAllianceListDataSerializer {

	/**
	 * Creates a new Get Invited To Join Alliance List Data Serializer.
	 */
	public GetInvitedToJoinAllianceListDataSerializer() {
		super(GetInvitedToJoinAllianceList.COMMAND_ID);
	}

	@Override
	public List<Integer> readReturnValue(IDataReader reader) throws IOException {
		List<Integer> value = reader.readIntegerObjectList(true, false);
		return value;
	}

	@Override
	public void writeReturnValue(IDataWriter writer, List<Integer> value) throws IOException {
		writer.writeIntegerObjectList(value, true, false);
	}

	@Override
	public IExecutableCommand<List<Integer>> readRequest(IDataReader reader) throws IOException {

		// Read fields
		long loginId = reader.readLong();
		int instanceId = reader.readInt();
		int allianceId = reader.readInt();

		// Create object
		GetInvitedToJoinAllianceList object = new GetInvitedToJoinAllianceList();
		object.setLoginId(loginId);
		object.setInstanceId(instanceId);
		object.setAllianceId(allianceId);
		return object;
	}

	@Override
	public void writeRequest(IDataWriter writer, IExecutableCommand<List<Integer>> argument) throws IOException {
		GetInvitedToJoinAllianceList object = (GetInvitedToJoinAllianceList) argument;

		// Get fields
		long loginId = object.getLoginId();
		int instanceId = object.getInstanceId();
		int allianceId = object.getAllianceId();

		// Write fields
		writer.writeLong(loginId);
		writer.writeInt(instanceId);
		writer.writeInt(allianceId);
	}

	@Override
	public IExecutableCommandResponse<List<Integer>> newResponse() {
		return new GetInvitedToJoinAllianceListResponse();
	}
}
